<?php


namespace app\common\middleware;


use app\merchant\system\service\MerAuthService;
use app\platform\system\service\PlatformAuthService;
use Webman\Http\Request;

class CommonMiddleware extends BaseAuthMiddleware
{
    protected function checkAndSetRequest(Request $request)
    {
        //根据前端在header传入的os判断当前在哪个系统
        $os = $request->header("os") ?: $request->header("Host") ?: "";
        if (str_contains($os, "merchant")) {
            //商户端
            MerAuthService::checkAndSetRequest($request, $this->token);
        }
        if (str_contains($os, "platform")) {
            //平台端
            PlatformAuthService::checkAndSetRequest($request, $this->token);
        }
    }

    protected function checkAuthRight(Request $request, callable $handler)
    {
        return $handler($request);
    }


}